import matplotlib.pyplot as plt
import plotly.express as px
import seaborn as sns
import plotly
plotly.offline.init_notebook_mode()
fig, ax1 = plt.subplots(figsize=(5, 2.7), layout = "constrained")
# Defining x and y data points
x =[4, 8, 16, 2, 3, 9, 18, 6, 5, 15, 10, 8, 6]
y =[64, 72, 96, 81, 88, 99, 108, 92, 86, 100, 69, 77, 80]
# Plotting the scatter plot between x and y
ax1.scatter(x, y, c = 'red', s = 100, alpha = 0.6)
# Setting the labels for x-axis and y-axis
ax1.set_xlabel("x-axis")
ax1.set_ylabel("y-axis")
ax1.set_title("Scatter Plot between x and y")
# enabling the grid view
ax1.grid(True)
# Importing the tips data
df = px.data.tips()
# Plotting the scatter plot for different weekdays between total_bill and tips
fig= px.scatter(df, x="total_bill", y = "tip", color="sex", size="size", facet_col="day")
fig.show()
# Importing the mpg data
cars = sns.load_dataset("mpg")
# Plotting the boxplot for mpg for different origins
sns.boxplot(x="origin", y="mpg", data=cars)
<Axes: xlabel='origin', ylabel='mpg'>
The above box plot indicates that, the Japanese cars have higher average mpg than European and American cars. European cars have less variability in their average mpg.
# Plotting the line plot between acceleartion and mpg for different regions
sns.lineplot(data = cars, x = "acceleration", y = "mpg", hue = "origin")
<Axes: xlabel='acceleration', ylabel='mpg'>
The accelearion and mpg have positive correlation. Japanese cars have higher mpg for standard acceleration. As per line plot, european cars have higher accelearion.